﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace CtrlSys
{
    public class InputBox : Form
    {
        Button confirmButton;
        Button cancelButton;
        Label tipLabel;
        TextBox messageBox;
        string _tip;
        public InputBox()
            : this(string.Empty, "请在下面输入：")
        {

        }

        public InputBox(string message)
            : this(message, "请在下面输入：")
        {

        }

        public InputBox(string message, string tip)
            : base()
        {
            this.Text = "输入对话框";
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.Opacity = 0.95;
            this.Size = new Size(300, 105);
            this.ShowInTaskbar = false;
            this.ControlBox = false;
            this.StartPosition = FormStartPosition.CenterParent;

            this.confirmButton = new Button();
            this.confirmButton.Text = "确定";
            this.confirmButton.Location = new Point(70, 50);
            this.confirmButton.Click += new EventHandler(confirmButton_Click);

            this.cancelButton = new Button();
            this.cancelButton.Text = "取消";
            this.cancelButton.Location = new Point(160, 50);
            this.cancelButton.Click += new EventHandler(cancelButton_Click);

            this.tipLabel = new Label();
            this.tipLabel.Text = tip;
            this.tipLabel.Location = new Point(10, 3);
            this.tipLabel.AutoSize = true;

            this.messageBox = new TextBox();
            this.messageBox.Size = new Size(275, 25);
            this.messageBox.Location = new Point(10, 20);
            this.messageBox.Text = message;
            this.messageBox.ImeMode = ImeMode.On;

            this.Controls.Add(confirmButton);
            this.Controls.Add(cancelButton);
            this.Controls.Add(tipLabel);
            this.Controls.Add(messageBox);
        }

        void confirmButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
        public string InputText
        {
            get
            {
                return messageBox.Text;
            }
            set
            {
                messageBox.Text = value;
            }
        }
    }
}
